/* 
Scenic Graphics Library
Copyright (C) 2007 Jouni Tulkki

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USApackage scenic;
*/

package scenic.toolkit;

import scenic.ScenicGraphics;
import scenic.toolkit.db.SyncVector;

public class TextView extends ComponentView {
	private ParagraphVector paragraphs;
	
	@SuppressWarnings("serial")
	private class ParagraphVector extends SyncVector<ParagraphView> {
		public ParagraphVector() {
			super(getModel().getParagraphs());
		}
		
		@Override
		public ParagraphView createObject(int index, Object sourceNode) {
			ParagraphView p = new ParagraphView((ParagraphModel)sourceNode, TextView.this);
			
			invalidate();
			return p;
		}

		@Override
		public void removeObject(int index, Object object) {
			invalidate();
		}		
	}
	
	public TextView(TextModel model) {
		super(model);
		paragraphs = new ParagraphVector();
	}
	
	public TextModel getModel() {
		return (TextModel)super.getModel();
	}
	
	public void paint(ScenicGraphics g) {
		g.clear();
		
		TextSetter textSetter = new TextSetter(getScene(), null, getWidth());
		
		for(int i = 0; i < paragraphs.size(); i++)
			paragraphs.elementAt(i).paint(textSetter);
		textSetter.flush();
	}
}
